package org.ichow.scenegame.model
{
	import com.greensock.events.LoaderEvent;
	import com.greensock.TweenLite;
	import flash.events.Event;
	import flash.media.Sound;
	import flash.net.URLRequest;
	import org.ichow.debug.Log;
	import org.puremvc.as3.patterns.proxy.Proxy;
	import com.greensock.loading.MP3Loader;
	
	/**
	 * ...
	 * @author M.ichow
	 */
	public class MusicProxy extends Proxy
	{
		public static const NAME : String = "MusicProxy";
		
		private var _url : String = "assets/sound/backgournd.mp3";
		private var _music : MP3Loader;
		private var _path : String;
		
		public function MusicProxy( path : String = "" , url : String = "" , data : Object = null )
		{
			super( NAME , data );
			_path = path;
			_url = url;
		}
		
		override public function onRegister() : void
		{
			super.onRegister();
			Log.trace( "++加载音乐" );
			_music = new MP3Loader( new URLRequest( _path + _url ) , { repeat: -1 , onComplete: completeHandler } );
			_music.load();
		}
		
		private function completeHandler( e : LoaderEvent ) : void
		{
			Log.trace( ">>音乐播放: " + _music.url );
			_music.playSound();
			setData( _music );
		}
		
		public function setVolume( v : Number = 0 ) : void
		{
			TweenLite.to( _music , 1 , { volume: v } );
			Log.trace( "@@设置声音: " + v );
		}
	
	}

}